<template>
  <div>
   <div>
     <el-form ref="passwordForm" :model="passwordForm" label-width="100px" class="demo-passwordForm">
       <el-alert
         title="导出数据"
         type="info"
         description="为了数据的安全性，导出操作需要输入密码如果忘记密码，请联系系统管理员重置"
         show-icon
       />
       <el-form-item label="输入密码" prop="password" >
         <el-input v-model="passwordForm.password" type="password"/>
       </el-form-item>
       <el-form-item>
         <el-button type="primary" @click="submitForm">导出数据</el-button>
         <el-button type="text" @click="openChangePassword = true">修改密码</el-button>
       </el-form-item>
     </el-form>
   </div>
    <el-dialog
      title="修改导出密码"
      :visible.sync="openChangePassword"
      width="30%"
      :modal="false"
      center>
      <el-form ref="changePasswordForm" :model="changePasswordForm" label-width="100px" class="demo-passwordForm">

        <el-form-item label="旧密码" prop="oldPassword" >
          <el-input v-model="changePasswordForm.oldPassword" type="password"/>
        </el-form-item>
        <el-form-item label="新密码" prop="newPassword" >
          <el-input v-model="changePasswordForm.newPassword" type="password"/>
        </el-form-item>
        <el-form-item label="确认新密码" prop="newPasswordAgain" >
          <el-input v-model="changePasswordForm.newPasswordAgain" type="password"/>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="openChangePassword = false">取 消</el-button>
    <el-button type="primary" @click="changePassword">确 定</el-button>
  </span>
    </el-dialog>
  </div>


</template>

<script>
  export default {
    props: {
      tableFiled: {},
      comment: {},
    },
    data() {
      return {
        passwordForm: {
          password: ''
        },
        openChangePassword:false,
        fileName: '',
        errCode:'',
        changePasswordForm: {
          oldPassword: '',
          newPassword: '',
          newPasswordAgain: ''
        },
      }
    },
    methods: {
      downLoad(fileName) {
        this.$download('dataCenter/downloadExportRecords', { fileName  }, fileName + '.xls')
      },
      submitForm(params1 = {}) {
        var columnComment = this.comment
        var params = JSON.stringify(params1)
        var tableFiled = this.tableFiled
        const password = this.passwordForm.password
        this.$post('dataCenter/exportData', {
          password , params, tableFiled, columnComment
        }).then((r) => {
          const fileName = r.data.fileName
          const errCode = r.data.code
          if(fileName == null){
            this.fileName == ''
          }else{
            this.fileName = fileName
          }
          this.errCode = errCode
          if(this.errCode == 0){
            this.downLoad(this.fileName);
          }
        })
      },
      changePassword(params1 = {}) {
        params1.oldPassword = this.changePasswordForm.oldPassword
        params1.newPassword = this.changePasswordForm.newPassword
        params1.newPasswordAgain = this.changePasswordForm.newPasswordAgain
        var params = JSON.stringify(params1)
        this.$post('dataCenter/changePassword', {
          params
        })
      }
    }
  }
</script>
